<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text" placeholder="请输入0-100之间的整数" id="i1">
<input type="button" value="猜一猜" onclick="f()">
<input type="button" value="充值10次" onclick="f1()">

<div>
    随机数为：<span id="s1"></span>结果：<span id="s2"></span>
</div>

<script>
    let x = parseInt(Math.random() * 101);
    let count = 0;
    let j = 5;
    let s1 = document.querySelector("#s1");
    s1.innerText = x;
    function f() {
        count++;
        j--;
        let i1 = document.querySelector("#i1");
        let s = document.querySelector("#s2");

        if (isNaN(i1.value)) {
            s.innerText = "输入错误！";
            return;
        }
        if (j > 0) {
            if (i1.value > x) {
                s.innerText = "猜大了,还剩" + j + "次";

            } else if (i1.value < x) {
                s.innerText = "猜小了,还剩" + j + "次";
            } else {
                s.innerText = "恭喜你猜对了，一共用了" + count + "次";
                count = 0;
                j = 5;
                x = parseInt(Math.random() * 101);
                s1.innerText = x;
            }
        } else {
            s.innerText = "次数不足，请充值！";
        }
    }

    function f1() {
        j+=10;
    }
</script>
</body>
</html>